import axios from "axios";
import type { AxiosInstance, AxiosRequestConfig } from "axios";

export interface ApiResponse<T> {
  code: number;
  data: T;
  msg: string;
}

export interface HttpRequestConfig extends AxiosRequestConfig {
  timeout?: number;
  apiType?: string;
}

interface CustomAxiosInstance extends AxiosInstance {
  post<T = any, R = ApiResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
}

const instance: CustomAxiosInstance = axios.create({
  baseURL: import.meta.env.VITE_API_BASE_URL,
  timeout: 10000,
  headers: { "Content-Type": "application/json" },
});

instance.interceptors.response.use((response: any) => {
  const res = response.data;
  return res;
});

export default instance;
